package com.model;

import java.util.ArrayList;

public class Family {
	

	public String name, description;
	public ArrayList<Person> persons = new ArrayList<Person>();
	public Person headOfFamilyMale, headOfFamilyWomen;
	
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public String getDescription() {
		return description;
	}
	
	public void setDescription(String description) {
		this.description = description;
	}
	
	public ArrayList<Person> getPersons() {
		return persons;
	}
	
	public void setPersons(ArrayList<Person> persons) {
		this.persons = persons;
	}
	
	//Only allow head of family
	public void addMember(Person person){
		if(!persons.contains(person)){
			this.persons.add(person);
			this.persons.add(person.getPartner());
			for(int i = 0; i < person.getChildren().size(); i++){
				Person p = person.getChildren().get(i);
				addMember(p);
			}
			
		}
	}
	
	//For test
	
	public void addHeadMale(Person p){
		headOfFamilyMale = p;
	}
	
	public void printFamily(){
		System.out.println(headOfFamilyMale);
		System.out.println(headOfFamilyMale.getPartner());
		printChildren(headOfFamilyMale, 1);
//		for(int i = 0; i < headOfFamilyMale.getChildren().size(); i++){
//			System.out.println(headOfFamilyMale.getChildren().get(i));
//		}
	}
	
	public void printChildren(Person p, int lvl){
		ArrayList<Person> children = p.getChildren();
		String gen = "";
		for(int j = 0; j < lvl; j++){
			gen = gen + "-";
		}
		for(int i = 0; i < children.size(); i++){
			System.out.println(gen + " " +children.get(i));
			if(children.get(i).getPartner() != null){
				System.out.println(gen + ">" + " " +children.get(i).getPartner() + "(Partner)");
			}
			
			printChildren(children.get(i), lvl++);
		}
	}
	
	

}
